import React from 'react';
import util from 'util';
import {Table } from 'antd';
import {SearchDemo, RightButton} from 'kpl';
import sys_dict from "sys_dict";

// 服务管理
class Tasklog extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            tblSource: [],
            totalCount: 0,
            isLoading: false,
            key:0
        };
        // 初始化查询参数
        this.searchParams={
            "page": 1,
            "rows": sys_dict.defaultPageSize.toString()
        };
    }
    // 渲染之后 1ew
    componentDidMount() {
        // 获取项目编号
        util.httpRequest({
            type: "POST", url: 'task050201.json', params: {},
            success: function (result) {
                if (result.ret_code == "0000") {
                    //  itemkey,itemvalue
                    let projectList=[];
                    for(let obj of result.rows){
                        projectList.push({itemkey:obj.id,itemval:obj.name});
                    }
                    let firstkey=projectList.length>0?projectList[0].itemkey:"";
                    console.log("list;",projectList);
                    this.searchParams.projectid=firstkey;
                    this.setState({
                        projectList:projectList,
                        defaultProKey: firstkey,
                        key:Math.random()
                    });
                    // 刷新情况
                    this.refresh(this.searchParams);
                }
            }.bind(this)
        });
    }

    // 刷新
    refresh(paramdic) {
        // 打开等待框
        this.setState({isLoading: true});
        util.httpRequest({
            type: "POST", url: 'task050401.json', params: paramdic,
            //plattype: 'app/',
            success: function (result) {
                if (result.ret_code == "0000") {
                    this.setState({
                        tblSource: result.rows,
                        totalCount: result.total
                    });
                }
            }.bind(this)
            ,complete: function () {
                this.setState({
                    isLoading: false
                })
            }.bind(this)
        });
    }

    // 查询 qweq
    search(params) {
        // 分页初始化
        params.page = "1";
        params.rows = sys_dict.defaultPageSize.toString();
        params.status=params.jobdeal_status;
        params.serchstart = util.date2str(params.serchstart);
        params.serchend = util.date2str(params.serchend);
        this.searchParams=params;
        this.refresh(params);
    }

    // pagesize改变
    onShowSizeChange(current, pageSize) {
        console.log(current, pageSize);
        let params = this.searchParams;
        params.rows = pageSize;
        params.page = current;
        this.refresh(params);
    }
    // page改变
    onChange(page) {
        console.log(page);
        let params = this.searchParams;
        params.page = page;
        this.refresh(params);
    }

    // 初始化配置 sadfqw
    config() {
        const pagination = {
            total: this.state.totalCount,
            showSizeChanger: true,
            showQuickJumper: true,
            pageSizeOptions: sys_dict.pageSizeOptions,
            defaultPageSize: sys_dict.defaultPageSize,
            onShowSizeChange: this.onShowSizeChange.bind(this),
            onChange: this.onChange.bind(this)
        };
        // 返回列表配置
        return {
            tableConfig: {
                scroll:{ x: 2000 },
                pagination: pagination,
                loading: this.state.isLoading,
                dataSource: this.state.tblSource,
                columns: [ {
                    title: '项目编号',
                    dataIndex: 'projectid',
                    key: 'projectid',
                    width:"110"
                }, {
                    title: '项目名称',
                    dataIndex: 'projectname',
                    key: 'projectname',
                    width:"100"
                },{
                    title: '任务编号',
                    dataIndex: 'jobid',
                    key: 'jobid',
                    width:"110"
                }, {
                    title: '任务名称',
                    dataIndex: 'jobname',
                    key: 'jobname',
                    width:"110"
                },{
                    title: '状态',
                    dataIndex: 'status',
                    key: 'status',
                    width:"70",
                    render: function (value, data, rowIndex) {
                        var str = util.convert("jobdeal_status", value.toString());
                        return str;
                    }
                }, {
                    title: '请求地址',
                    dataIndex: 'link',
                    key: 'link'
                },{
                    title: '调度结果',
                    dataIndex: 'result',
                    key: 'result'
                }, {
                    title: '服务编号',
                    dataIndex: 'servicecode',
                    key: 'servicecode'
                },  {
                    title: '签名详情',
                    dataIndex: 'signstringtask',
                    key: 'signstringtask'
                },  {
                    title: '请求参数',
                    dataIndex: 'paramstask',
                    key: 'paramstask'
                },  {
                    title: '创建时间',
                    dataIndex: 'addtime',
                    key: 'addtime',
                    render: function (value, data, rowIndex) {
                        var str = util.dateStrFormat(value, "D")+" "+util.dateStrFormat(value, "T");
                        return str;
                    }
                }, {
                    title: '更新时间',
                    dataIndex: 'updatetime',
                    key: 'updatetime',
                    render: function (value, data, rowIndex) {
                        var str = util.dateStrFormat(value, "D")+" "+util.dateStrFormat(value, "T");
                        return str;
                    }
                }]
            }
        };
    }

    // 渲染
    render() {
        let config = this.config();

        const searchConfig = {
            searchTitle: "查询日志",
            searchInit: {
                projectid:this.state.defaultProKey
            },
            searchField: [
                [
                    {propsname: "项目编号", propsKey: "projectid", propsType: "select", key: "1111",optionData:this.state.projectList
                    },
                    {propsname: "状态",propsKey: "jobdeal_status",propsType: "select",key: "1113"}
                ],
                [
                    {propsname: "开始日期：", propsKey: "serchstart", propsType: "datepicker", key: "6666"},
                    {propsname: "结束日期：", propsKey: "serchend", propsType: "datepicker", key: "7777"}
                ]
            ]
        };

        return (
            <div>
                <SearchDemo key={this.state.key} search={this.search.bind(this)} searchConfig={searchConfig}></SearchDemo>
                <Table {...config.tableConfig}></Table>
            </div>
        );
    }
}

export default Tasklog;